/*
 [ ----- BOXLIB: DHTML BOX LIBRARY ----- ]
 [ Version 1.0.20030701: Initial release ]
 [ ------------------------------------- ]
 [ (C) 2003 Scott Schiller. Distribution ]
 [ allowed provided this notice is left  ]
 [ intact and unedited within this file. ]
 [ Source: http://www.schillmania.com    ]
 [ ------------------------------------- ]
*/

var ns60Fix = ns60Fix || false;

function BoxLibItem(parent) {
  this.o = parent;
  this.corners = [];
  this.classNames = ['topLeft','topRight','bottomLeft','bottomRight'];
  this.content = this.o.getElementsByTagName('div')[0];
  this.shadow = document.createElement('div');
  this.shadow.className = 'shadow';
  this.o.appendChild(this.shadow);
  this.boxColor = 'ffffff';

  this.reflow = function() {
    // workaround for redraw bug when dynamically writing content
    this.o.style.height = (this.o.style.height?'':'auto');
  }
  this.resizeHandler = function() {
    this.corners[1].style.right = this.corners[3].style.right = ((this.content.offsetWidth+1)%2==0?-1:0)+'px';
    this.corners[2].style.bottom = this.corners[3].style.bottom = ((this.content.offsetHeight+1)%2==0?-1:0)+'px';
  }
  this.setBGImage = function(bgImage) {
    this.bgImage = bgImage;
    this.o.style.backgroundImage = 'url(image/box_highlight_'+this.bgImage+'.gif)';
    this.shadow.style.backgroundImage = 'url(image/box_shadow_'+this.bgImage+'.gif)';
  }
  this.setColor = function(color) {
    this.color = color;
    for (var i=0; i<this.corners.length; i++) {
      this.applyColor(i);
    }
  }
  for (var i=0; i<4; i++) {
    this.corners[i] = document.createElement('div');
    with (this.corners[i]) {
      className = 'corner ' + this.classNames[i];
      style.width = '4px';
      style.height = '4px';
    }
    parent.appendChild(this.corners[i]);
  }
}

function BoxLibController() {
  var self = this;
  this.resizeHandler = function() {
    for (var i=0; i<self.boxes.length; i++) {
      self.boxes[i].resizeHandler();
    }
  }
  this.aN = navigator.appName;
  this.aV = navigator.appVersion.toLowerCase();
  this.ua = navigator.userAgent.toLowerCase();
  this.isIE = (this.aN.indexOf('Microsoft')+1?1:0);
  this.is5 = (this.isIE && (this.aV.indexOf('MSIE 5')+1));
  this.isNS60 = (this.aN.indexOf('Netscape')+1 && this.ua.indexOf('/6.0')+1);
  this.isMac = (this.aV.indexOf('mac')+1?1:0);
  this.isWin = (this.aV.indexOf('win')+1);
  if (this.isIE && this.isMac) {
    return false;
  }
  if (this.isIE && this.isWin) {
    window.onresize = self.resizeHandler;
  }
  /* // used in standalone
  this.css = document.createElement('link');
  this.css.rel = 'stylesheet';
  this.css.type = 'text/css';
  this.css.href = 'boxlib.css';
  this.head.appendChild(this.css);
  */
  
  var divs = document.getElementsByTagName('div');
  this.boxes = [];
  this.boxCount = 0;
  for (var i=0; i<divs.length; i++) {
    if (divs[i].className.indexOf('box')+1) {
      this.boxes[this.boxes.length] = new BoxLibItem(divs[i]);
      if (this.isIE) this.boxes[this.boxes.length-1].resizeHandler(); // fix for IE with odd widths
      if (this.isNS60 && ns60Fix) divs[i].style.position = 'relative';
      this.boxCount++;
    }
  }
}

function BoxLibLoader() {
  // stupid ie:mac workaround
/*  
  if ((navigator.appName.indexOf('Microsoft')+1?1:0) && (navigator.appVersion.toLowerCase().indexOf('mac')+1?1:0)) {
    document.open('text/html');
    document.write('<link rel="stylesheet" type="text/css" href="boxlib.css" />\n');
    document.close();
  }

  this.links = document.getElementsByTagName('link');
  this.css = null;
  for (var i=0; i<this.links.length; i++) {
    if (this.links[i].title == 'boxlib') {
      this.css = this.links[i];
      this.css.disabled = false;
    }
  }
  
  if (!this.css) {
    window.status = 'BoxLibController() Warning: Could not find "boxlib" LINK element.'
  }
*/
  window.onload = function() {
    jsOnLoad();
    if (!(ua.indexOf('netscape')+1 && uaVer.indexOf('4.')+1)) {
      var bC = new BoxLibController();
    }
  }
}

var jsOnLoad = window.onload || function() {};
var ua = navigator.appName.toLowerCase();
var uaVer = navigator.appVersion.toLowerCase();

var boxLibLoader = new BoxLibLoader();
